package com.fdb.efp.cus.api.rest;

import java.util.List;
import java.util.Objects;

import com.fdb.basic.framework.core.constant.ApplicationConstance;
import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.core.util.TimeUtil;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.cus.service.facade.PartnerPrdInfoService;
import com.fdb.efp.cus.service.vo.PartnerPrdInfoVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/api")
public class PartnerPrdInfoController extends AbstractController {

	@Autowired
	@Qualifier("partnerPrdInfoService")
	private PartnerPrdInfoService partnerPrdInfoService;


	/**
	 * 列表数据查询
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value="/partner/prd/infos", method=RequestMethod.POST)
	public @ResponseBody
	ResponseData<List<PartnerPrdInfoVO>> queryPartnerPrdInfoAll(
			@RequestBody PartnerPrdInfoVO vo) {
//		List<PartnerPrdInfoVO> outputVo = this.executeQueryList("queryAll", partnerPrdInfoService, new Object[]{vo});
		List<PartnerPrdInfoVO> outputVo =partnerPrdInfoService.queryAllOwner(vo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键查询详情
	 * @return
	 */
	@RequestMapping(value="/partner/prd/info/{partnerId}", method=RequestMethod.GET)
	public @ResponseBody ResponseData<PartnerPrdInfoVO> queryByPk(@PathVariable("partnerId") String partnerId) {
		PartnerPrdInfoVO inVo = new PartnerPrdInfoVO();
		inVo.setPartnerId(partnerId);
		PartnerPrdInfoVO outputVo = partnerPrdInfoService.queryByPk(inVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键删除信息
	 * @param partnerPrdInfo
	 * @return
	 */
	@RequestMapping(value="/partner/prd/info", method=RequestMethod.DELETE)
	public @ResponseBody ResponseData<Integer> deleteByPk(@RequestBody PartnerPrdInfoVO inPartnerPrdInfoVo) {
		int outputVo = partnerPrdInfoService.deleteByPk(inPartnerPrdInfoVo);
		return getResponseData(outputVo);

	}

	/**
	 * 根据主键更新信息
	 * @param inPartnerPrdInfoVo
	 * @return
	 */
	@RequestMapping(value="/partner/prd/info", method=RequestMethod.PUT)
	public @ResponseBody ResponseData<Integer> updateByPk(@RequestBody PartnerPrdInfoVO inPartnerPrdInfoVo) {
		setUserInfoToVO(inPartnerPrdInfoVo );
		inPartnerPrdInfoVo.setLastUpdateUser(inPartnerPrdInfoVo.getLoginUserId());
		inPartnerPrdInfoVo.setLastUpdateTime(TimeUtil.getCurrentDateTime());
		int outputVo = partnerPrdInfoService.updateByPk(inPartnerPrdInfoVo);
		return getResponseData(outputVo);

	}

	/**
	 * 新增数据
	 * @param inPartnerPrdInfoVo
	 * @return
	 */
	@RequestMapping(value="/partner/prd/info", method=RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertPartnerPrdInfo(@RequestBody PartnerPrdInfoVO inPartnerPrdInfoVo) {
		setUserInfoToVO(inPartnerPrdInfoVo );
		PartnerPrdInfoVO tempVo = partnerPrdInfoService.queryByPartnerAndPrdId(inPartnerPrdInfoVo);
		if (Objects.nonNull(tempVo)) {
			ResponseData<Integer> responseData = new ResponseData<Integer>();
			responseData.setMessage("产品编号是：【" + inPartnerPrdInfoVo.getPrdId() + "】的合作方关联产品已存在！");
			responseData.setCode(ApplicationConstance.FAILURE);
			responseData.setSuccess(false);
			return responseData;
		}

		inPartnerPrdInfoVo.setCreateUser(inPartnerPrdInfoVo.getLoginUserId());
		inPartnerPrdInfoVo.setCreateTime(TimeUtil.getCurrentDateTime());
		int outputVo = partnerPrdInfoService.insertPartnerPrdInfo(inPartnerPrdInfoVo);
		return getResponseData(outputVo);

	}
}
